package com.koocloud.electroplatemanage.controller;

import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.TypeWorkVo;
import com.koocloud.electroplatemanage.pojo.WorkTimeVo;
import com.koocloud.electroplatemanage.service.DrawNoService;
import com.koocloud.electroplatemanage.service.TypeWorkService;
import com.koocloud.electroplatemanage.service.WorkTimeService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: electroplatemanage
 * @description: 工时控制类
 * @author: zww
 * @create: 2020-09-29 16:25
 */
@RestController
@RequestMapping("/worktime")
public class WorkTimeController {
    static Logger log = Logger.getLogger("worktime");
    @Autowired
    WorkTimeService workTimeService;
    @Autowired
    DrawNoService drawNoService;
    @Autowired
    TypeWorkService typeWorkService;

    /**
     * @Description:通过pk查询工时表一条记录
     * @Param: [pk]
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate
     * @Author: zww
     * @date: 2020/9/30
     */
    @RequestMapping(value = "/selectByPk", method = RequestMethod.POST, name = "主键查询")
    public ResponseTemplate selectByPk(@RequestParam(name="pkWorkTime") String pk) {
        log.info("传入的参数pkWorkTime:"+pk);
        //通过pk查询工时表的一条记录
        return workTimeService.selectByPk(pk);
    }
    /**
     *@Description: 通过图号和工种查询一条记录
     *@Param: [drawNoCode, typeWorkCode]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/10
     */
    @RequestMapping(value = "/selectByDrawNoTypeWork", method = RequestMethod.POST, name = "通过图号和工种查询")
    public ResponseTemplate selectByDrawNoTypeWork(@RequestParam(name="drawNoCode") String drawNoCode,@RequestParam(name="typeWorkCode") String typeWorkCode) {
        log.info("传入的参数drawNoCode："+drawNoCode+",typeWorkCode："+typeWorkCode);
        //通过图号+工种查询工时表的一条记录
        return workTimeService.selectByDrawNoTypeWork(drawNoCode,typeWorkCode);

    }

    /**
     * @Description: 查询所有记录 分页 姓名 工时
     * @Param: [page,limit,workTime]
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate
     * @Author: zww
     * @date: 2020/9/30
     */
    @RequestMapping(value = "/selectAllData", method = RequestMethod.POST, name = "全表查询")
    public ResponseTemplate selectAllData(String page, String limit, WorkTimeVo workTimeVo) {
        log.info("工时查询所有记录参数page:"+page+"limit:"+limit+"workTimeVo:"+workTimeVo);
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }
        //查询所有记录 分页
        return workTimeService.selectAllData(page,limit,workTimeVo);
    }

    /**
     *@Description: 校验填写的工时表主键
     *@Param: [workTimeVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/16
     */
    @RequestMapping(value = "/check", method = RequestMethod.POST, name = "校验填写的工时表主键")
    public ResponseTemplate check(@RequestBody WorkTimeVo workTimeVo) {
        log.info("工时校验填写的工时表主键参数workTimeVo:"+workTimeVo);
        //校验填写的分配工作表主键
        return workTimeService.check(workTimeVo);

    }
    /**
     *@Description:插入一条记录
     *@Param: [workTimeVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST, name = "新增一条数据")
    public ResponseTemplate insert(@RequestBody WorkTimeVo workTimeVo) {
        log.info("工时插入一条记录参数workTimeVo:"+workTimeVo);
        //插入一条记录
        return workTimeService.insert(workTimeVo);
    }
    /**
     *@Description:批量插入记录
     *@Param: [listWorkTimeVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/batchInsert", method = RequestMethod.POST, name = "批量新增数据")
    public ResponseTemplate batchInsert(@RequestBody List<WorkTimeVo> listWorkTimeVo) {
        log.info("工时批量插入记录参数listWorkTimeVo:"+listWorkTimeVo);
        //批量插入记录
        return workTimeService.batchInsert(listWorkTimeVo);
    }
    /**
     *@Description:逻辑删除一条记录
     *@Param: [pk]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, name = "逻辑删除一条记录")
    public ResponseTemplate delete(@RequestParam(name="workTimeCode") String pk,@RequestParam(name="deleteFlag") String deleteFlag) {
        log.info("工时逻辑删除记录参数pk:"+pk+"deleteFlag:"+deleteFlag);
        //逻辑删除一条记录
        return workTimeService.delete(pk,deleteFlag);
    }
    /**
     *@Description:通过pks批量逻辑删除记录
     *@Param: [listPks]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/batchDeleteByPks", method = RequestMethod.POST, name = "批量逻辑删除记录")
    public ResponseTemplate batchDeleteByPks(@RequestBody List<String> listPks) {
        log.info("工时批量逻辑删除记录参数listPks:"+listPks);
        //通过pks批量逻辑删除记录
        return workTimeService.batchDeleteByPks(listPks);
    }
    /**
     *@Description:修改一条记录
     *@Param: [typeWorkVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, name = "修改一条记录")
    public ResponseTemplate update(@RequestBody WorkTimeVo workTimeVo) {
        log.info("修改一条记录参数workTimeVo:"+workTimeVo);
        //修改一条记录
        return workTimeService.update(workTimeVo);
    }

    /**
     *@Description: 获取现有的所有图号
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/19
     */
    @RequestMapping(value = "/selectDrawNo", method = RequestMethod.POST, name = "获取现有的所有图号")
    public ResponseTemplate selectDrawNo(String idOrName){
        log.info("传入的参数idOrName:"+idOrName);
        return drawNoService.selectDrawNo(idOrName);

    }


    /**
     *@Description: 获取现有的所有工种
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/19
     */
    @RequestMapping(value = "/selectTypeWork", method = RequestMethod.POST, name = "获取现有的所有工种")
    public ResponseTemplate selectTypeWork(String idOrName){
        log.info("传入的参数idOrName:"+idOrName);
        return typeWorkService.selectTypeWork(idOrName);

    }
}